<%@page import="com.zt.exp5.bean.Car"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

</head>

<body>
	<%
		Car car = (Car) session.getAttribute("car");

		if (car == null) {
			car = new Car();
			session.setAttribute("car", car);
		}
		request.setCharacterEncoding("utf-8");

		String action = (String) request.getParameter("action");
		if ("buy".equals(action)) {
			int id = Integer.parseInt((String) request.getParameter("id"));
			car.buy(id, 1);
			request.getRequestDispatcher("buy3.jsp").forward(request,
					response);
		} else if ("showCar".equals(action)) {
			request.getRequestDispatcher("showCar3.jsp").forward(request,
					response);
		} else if ("remove".equals(action)) {
			int id = Integer.parseInt((String) request.getParameter("id"));
			car.remove(id, 1);
			request.getRequestDispatcher("showCar3.jsp").forward(request,
					response);
		} else if ("clear".equals(action)) {
			car.clear();
			request.getRequestDispatcher("showCar3.jsp").forward(request,
					response);
		} else if ("addProduct".equals(action)) {
			String name = request.getParameter("name");
			double price = Double
					.parseDouble(request.getParameter("price"));
			car.addProduct(name, price);
			request.getRequestDispatcher("buy3.jsp").forward(request,
					response);
		}
	%>
</body>
</html>
